package com.study.zzedu.ui.evaluate;

import android.content.Context;
import android.text.TextUtils;

import com.study.zzedu.base.BaseModel;
import com.study.zzedu.http.OnResultListener;
import com.study.zzedu.utils.AppConstant;
import com.study.zzedu.utils.LogUtil;
import com.study.zzedu.utils.OkHttpUtils;

import org.json.JSONObject;

public class EvaluateModel extends BaseModel {

    public void getEvaluateInfoList(Context context, final OnResultListener resultListener){

        OkHttpUtils.getInstance(context).getJsonForString(OkHttpUtils.BASE_URL + "/appCourseAssess/queryCourseAssess",
                null, null, new OkHttpUtils.HttpCallBack() {
                    @Override
                    public void onSuccess(String obj) {
                        try {
                            JSONObject jObject = new JSONObject(obj);
                            if (0 == jObject.getInt("code")) {
                                LogUtil.e("Forget", "课程评价项目列表成功");
                                resultListener.onSuccess(obj);
                            } else {
                                LogUtil.e("Forget", "课程评价项目列表失败");
                                resultListener.onError(jObject.get("message").toString());
                            }
                        } catch (Exception e) {
                            e.toString();
                        }
                    }

                    @Override
                    public void onSuccess(JSONObject obj) {
                        //resultListener.onSuccess(obj.toString());
                    }

                    @Override
                    public void onError(String msg) {
                        LogUtil.e("Forget", "课程评价项目列表失败");
                        resultListener.onError(msg);
                    }
                });
    }
    public void submitData(Context context, String userCode,String courseCode,String subjectCodes,String scores,String content,final OnResultListener resultListener){
        if (TextUtils.isEmpty(AppConstant.userCode)) {
            LogUtil.e("Forget", "学号异常");
            return;
        }
        OkHttpUtils.getInstance(context).getJsonForString(OkHttpUtils.BASE_URL + "/appCourseAssess/insertCourseAssess",
                new String[]{"userCode","courseCode","subjectCodes","scores","content"}, new String[]{userCode,courseCode,subjectCodes,scores,content}, new OkHttpUtils.HttpCallBack() {
                    @Override
                    public void onSuccess(String obj) {
                        try {
                            JSONObject jObject = new JSONObject(obj);
                            if (0 == jObject.getInt("code")) {
                                LogUtil.i("Forget", "发布课程评价内容成功");
                                resultListener.onSuccess(obj);
                            } else {
                                LogUtil.e("Forget", "发布课程评价内容失败");
                                resultListener.onError(jObject.get("message").toString());
                            }
                        } catch (Exception e) {
                            e.toString();
                        }
                    }

                    @Override
                    public void onSuccess(JSONObject obj) {
                        //resultListener.onSuccess(obj.toString());
                    }

                    @Override
                    public void onError(String msg) {
                        LogUtil.i("Forget", "发布课程评价内容失败");
                        resultListener.onError(msg);
                    }
                });
    }

    public void checkUserCourseAssess(Context context,String courseCode,final OnResultListener resultListener){

        OkHttpUtils.getInstance(context).getJsonForString(OkHttpUtils.BASE_URL + "/appCourseAssess/checkUserCourseAssess",
                new String[]{"courseCode"}, new String[]{courseCode}, new OkHttpUtils.HttpCallBack() {
                    @Override
                    public void onSuccess(String obj) {
                        try {
                            JSONObject jObject = new JSONObject(obj);
                            if (0 == jObject.getInt("code")) {
                                LogUtil.i("Forget", "查询是否允许课程评价成功");
                                resultListener.onSuccess(obj);
                            } else {
                                LogUtil.e("Forget", "查询是否允许课程评价失败");
                                resultListener.onError(jObject.get("message").toString());
                            }
                        } catch (Exception e) {
                            e.toString();
                        }
                    }

                    @Override
                    public void onSuccess(JSONObject obj) {
                        //resultListener.onSuccess(obj.toString());
                    }

                    @Override
                    public void onError(String msg) {
                        LogUtil.i("Forget", "查询是否允许课程评价失败");
                        resultListener.onError(msg);
                    }
                });
    }
}
